﻿var Order_MainStore;
var Order_MainGridPanel;
var cellWidth1 = 100; //单元格宽度
var cellWidth2 = 100;
var topInputWidth = 100;
var cbClientInfo;
var order_id = -1;
var EditCellValue;
var ThisCellOleValue;
var hidValue;
var ModelRow;
var CurrentModelRow;
var CurrentEditOgId;
var isShowScrollBar = false;
var OrderPo;
var OrderDate;
var isUpdate = false;

Ext.onReady(function() {

    Ext.QuickTips.init();
    // 本地加载图片代码
    Ext.BLANK_IMAGE_URL = strPath + 'extjs/resources/images/default/s.gif';

    cellWidth1 = parseInt((parent.Ext.get("ContentFrame").getWidth() - 124) * 0.15);
    cellWidth2 = parseInt(parent.Ext.get("ContentFrame").getWidth() - 124 - (cellWidth1 * 3) - 68);

    topInputWidth = (parent.Ext.get("ContentFrame").getWidth() - 300) / 3;
    document.getElementById("txt_order_po").style.width = document.getElementById("txt_order_date").style.width = topInputWidth;

    order_id = GetParastr("order_id"); //获取地址栏参数

    //打印订单
    Ext.get('btnPrintOrder').on("click", function(e, t) {
        if (!isNaN(order_id) && order_id != 0)
            PrintOrder(order_id);
    });

    //打印小单
    Ext.get('btnPrintMO').on("click", function(e, t) {
        if (!isNaN(order_id) && order_id != 0)
            PrintMO(order_id);
    });

    //选择列事件
    var smOrder_MainModel = new Ext.grid.CheckboxSelectionModel({
        singleSelect: false,
        hidden: true,
        listeners: {
            rowselect: function(sm, row, rec) {
                ModelRow = row;
            }
        }
    });

    var httpProxyOrder_Main = new Ext.data.HttpProxy({
        url: strPath + 'GGFW/DocumentsManage/OrderCommand.fwf?Method=GetViewOrdersInfo'
    });

    var readerProxyOrder_Main = new Ext.data.JsonReader({
        root: 'Records',
        id: 'HWTransferItemID',
        totalProperty: 'totalCount',
        fields: [
            { name: 'id' }
          , { name: 'order_id' }
          , { name: 'order_po' }
          , { name: 'client_id' }
          , { name: 'client_name' }
          , { name: 'code' }
          , { name: 'pro_name' }
          , { name: 'color_num' }
          , { name: 'total' }
          , { name: 'kailiao' }
          , { name: 'memo' }
          , { name: 'order_date' }
        ]
    });

    // 数据源
    Order_MainStore = new Ext.data.Store({
        proxy: httpProxyOrder_Main,
        reader: readerProxyOrder_Main,
        remoteSort: true
    });

    // 加载后
    Order_MainStore.on('load', function() {
        if (Order_MainStore.getTotalCount() > 0) {
            document.getElementById("txt_order_po").value = Order_MainStore.getAt(0).get("order_po");
            OrderPo = document.getElementById("txt_order_po").value;
            document.getElementById("hid_client_id").value = Order_MainStore.getAt(0).get("client_id");
            cbClientInfo.setValue(Order_MainStore.getAt(0).get("client_name"));
            document.getElementById("txt_order_date").value = Order_MainStore.getAt(0).get("order_date").dateFormat("Y-m-d");
            OrderDate = document.getElementById("txt_order_date").value;
        }
        else
            V_OrdersStore.load({ params: { start: 0, limit: 500, order_id: order_id} });
    });

    var httpProxyV_Orders = new Ext.data.HttpProxy({
        url: strPath + 'GGFW/DocumentsManage/OrderCommand.fwf?Method=GetViewOrders'
    });

    var readerProxyV_Orders = new Ext.data.JsonReader({
        root: 'Records',
        id: 'HWTransferItemID',
        totalProperty: 'totalCount',
        fields: [
            { name: 'order_id' }
          , { name: 'order_po' }
          , { name: 'order_date' }
          , { name: 'isdeleted' }
          , { name: 'client_id' }
          , { name: 'client_name' }
        ]
    });

    // 数据源
    V_OrdersStore = new Ext.data.Store({
        proxy: httpProxyV_Orders,
        reader: readerProxyV_Orders,
        remoteSort: true
    });

    // 加载后
    V_OrdersStore.on('load', function() {
        if (V_OrdersStore.getTotalCount() > 0) {
            document.getElementById("txt_order_po").value = V_OrdersStore.getAt(0).get("order_po");
            OrderPo = document.getElementById("txt_order_po").value;
            document.getElementById("hid_client_id").value = V_OrdersStore.getAt(0).get("client_id");
            cbClientInfo.setValue(V_OrdersStore.getAt(0).get("client_name"));
            document.getElementById("txt_order_date").value = V_OrdersStore.getAt(0).get("order_date").dateFormat("Y-m-d");
            OrderDate = document.getElementById("txt_order_date").value;
        }
    });


    /**************产品ID,款名下载框***************/
    var ProductOrderNameRecordStore = new Ext.data.Store({
        //设定读取的地址
        proxy: new Ext.data.HttpProxy({ url: strPath + 'GGFW/DocumentsManage/ProductOrderCommand.fwf?Method=SearchValidProductOrder&Type=Pro_Name' }),
        //设定读取的格式
        reader: new Ext.data.JsonReader({
            root: 'Records',
            id: 'pro_id',
            totalProperty: 'totalCount',
            fields: [
                 { name: 'pro_id' }
			    , { name: 'code' }
				, { name: 'pro_name' }
           ]
        }),
        remoteSort: true
    });

    // 搜索结果
    var resultTpProductOrderName = new Ext.XTemplate(
            '<table style="width:100%;"><tr style="background:#ccc;"><th>#</th><th>款名</th><th>编号</th></tr>',
            '<tpl for=".">',
            '<tr class="search-item"><td>{#}</td><td>{pro_name}</td><td >{code}</td></tr>',
            '</tpl></table>'
        );

    var ProductOrderCodeRecordStore = new Ext.data.Store({
        //设定读取的地址
        proxy: new Ext.data.HttpProxy({ url: strPath + 'GGFW/DocumentsManage/ProductOrderCommand.fwf?Method=SearchValidProductOrder&Type=Pro_Code' }),
        //设定读取的格式
        reader: new Ext.data.JsonReader({
            root: 'Records',
            id: 'pro_id',
            totalProperty: 'totalCount',
            fields: [
                 { name: 'pro_id' }
			    , { name: 'code' }
				, { name: 'pro_name' }
           ]
        }),
        remoteSort: true
    });

    // 搜索结果
    var resultTpProductOrderCode = new Ext.XTemplate(
            '<table style="width:100%;"><tr style="background:#ccc;"><th>#</th><th>编号</th><th>款名</th></tr>',
            '<tpl for=".">',
            '<tr class="search-item"><td>{#}</td><td>{code}</td><td >{pro_name}</td></tr>',
            '</tpl></table>'
        );
    /*****************************/
    var Order_MainlistColumnModel = new Ext.grid.ColumnModel([
    	smOrder_MainModel,
	    { id: 'order_id', header: "order_id", align: 'center', sortable: false, hidden: true, dataIndex: 'order_id' }
	    , { id: 'pro_id', header: "pro_id", align: 'center', sortable: false, hidden: true, dataIndex: 'pro_id' }
	    , { id: 'grid_id', header: '序', width: 30, align: 'left', sortable: false, renderer: renderGridID }
	    , { id: 'code', header: "编号", align: 'center', width: cellWidth1, sortable: false, hidden: false, dataIndex: 'code', renderer: renderValue, editor: new Ext.form.ComboBox({
	        displayField: 'ProductOrder',
	        loadingText: '加载中...',
	        minChars: 1,
	        listWidth: 300,
	        minListWidth: 300,
	        deferHeight: true,
	        baseCls: "x-plain",
	        id: 'cbProductOrder_Code',
	        pageSize: 10,
	        store: ProductOrderCodeRecordStore,
	        selectOnFocus: true,
	        itemSelector: 'tr.search-item',
	        typeAhead: false,
	        mode: 'remote',
	        triggerAction: 'all',
	        tpl: resultTpProductOrderCode,
	        readOnly: false,
	        editable: true,
	        listeners:
            {
                focus: function() {
                    EditCellValue = null;
                    ThisCellOleValue = this.value;
                    CurrentModelRow = ModelRow;
                    CurrentEditOgId = Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('id')
                    hidValue = Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('pro_id');
                },
                blur: function() {
                    if (EditCellValue == null) {
                        EditCellValue = this.getValue();
                    }
                    if (hidValue == Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('pro_id')) {
                        if (EditCellValue != ThisCellOleValue) {
                            Order_MainGridPanel.getStore().getAt(CurrentModelRow).set('code', ThisCellOleValue);
                            Order_MainGridPanel.getView().refresh();
                            Ext.MessageBox.alert("提示", "<span style='line-height:18px;'>非法操作！<br /><font color='Red'>编号必须通过下拉列表选择获取！</font><br />数据已重置，请重新选择。</span>");
                        }
                    }
                    else
                        UpdateOrdersGridCellValue('pro_id', Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('pro_id'), CurrentEditOgId);
                },
                select: function selectvalue(combo, record, index) {
                    Ext.get("cbProductOrder_Code").dom.value = record.data.code;
                    Order_MainGridPanel.getStore().getAt(CurrentModelRow).set('pro_id', record.data.pro_id);
                    Order_MainGridPanel.getStore().getAt(CurrentModelRow).set('pro_name', record.data.pro_name);
                    EditCellValue = record.data.pro_name;
                    this.collapse();
                },
                specialkey: function(textfield, e) {
                    if (e.getKey() == Ext.EventObject.ENTER) {
                        EditCellValue = null;
                        Order_MainGridPanel.getSelectionModel().selectNext();
                    }
                }
            }
	    })
	    }
	    , { id: 'pro_name', header: "款名", align: 'center', width: cellWidth1, sortable: false, hidden: false, dataIndex: 'pro_name', renderer: renderValue, editor: new Ext.form.ComboBox({
	        displayField: 'ProductOrder',
	        loadingText: '加载中...',
	        minChars: 1,
	        listWidth: 300,
	        minListWidth: 300,
	        deferHeight: true,
	        baseCls: "x-plain",
	        id: 'cbProductOrder_Name',
	        pageSize: 10,
	        store: ProductOrderNameRecordStore,
	        selectOnFocus: true,
	        itemSelector: 'tr.search-item',
	        typeAhead: false,
	        mode: 'remote',
	        triggerAction: 'all',
	        tpl: resultTpProductOrderName,
	        readOnly: false,
	        editable: true,
	        listeners:
            {
                focus: function() {
                    EditCellValue = null;
                    ThisCellOleValue = this.value;
                    CurrentModelRow = ModelRow;
                    CurrentEditOgId = Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('id')
                    hidValue = Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('pro_id');
                },
                blur: function() {
                    if (EditCellValue == null) {
                        EditCellValue = this.getValue();
                    }
                    if (hidValue == Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('pro_id')) {
                        if (EditCellValue != ThisCellOleValue) {
                            Order_MainGridPanel.getStore().getAt(CurrentModelRow).set('pro_name', ThisCellOleValue);
                            Order_MainGridPanel.getView().refresh();
                            Ext.MessageBox.alert("提示", "<span style='line-height:18px;'>非法操作！<br /><font color='Red'>款名必须通过下拉列表选择获取！</font><br />数据已重置，请重新选择。</span>");
                        }
                    }
                    else
                        UpdateOrdersGridCellValue('pro_id', Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('pro_id'), CurrentEditOgId);
                },
                select: function selectvalue(combo, record, index) {
                    Ext.get("cbProductOrder_Name").dom.value = record.data.pro_name;
                    Order_MainGridPanel.getStore().getAt(CurrentModelRow).set('pro_id', record.data.pro_id);
                    Order_MainGridPanel.getStore().getAt(CurrentModelRow).set('code', record.data.code);
                    EditCellValue = record.data.pro_name;
                    this.collapse();
                },
                specialkey: function(textfield, e) {
                    if (e.getKey() == Ext.EventObject.ENTER) {
                        EditCellValue = null;
                        Order_MainGridPanel.getSelectionModel().selectNext();
                    }
                }
            }
	    })
	    }
        , { id: 'color_num', header: "颜色/数量", width: cellWidth2, align: 'center', sortable: false, dataIndex: 'color_num', renderer: renderValue, editor: new Ext.form.TextField({
            listeners: {
                focus: function() {
                    EditCellValue = null;
                    ThisCellOleValue = this.value;
                    CurrentModelRow = ModelRow;
                    CurrentEditOgId = Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('id')
                },
                blur: function() {
                    if (EditCellValue == null) {
                        EditCellValue = this.getValue();
                    }
                    if (EditCellValue != ThisCellOleValue) {
                        isUpdate = false;
                        UpdateTotalValue('color_num', ThisCellOleValue, EditCellValue, CurrentModelRow);
                        if (isUpdate) {
                            UpdateOrdersGridCellValue('color_num', EditCellValue, CurrentEditOgId);
                            UpdateOrdersGridCellValue('total', Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('total'), CurrentEditOgId);
                        }
                    }
                },
                specialkey: function(textfield, e) {
                    if (e.getKey() == Ext.EventObject.ENTER) {
                        EditCellValue = null;
                        Order_MainGridPanel.getSelectionModel().selectNext();
                    }
                }
            }
        }
        )
        }
        , { id: 'total', header: "总数", align: 'center', width: 68, sortable: false, dataIndex: 'total' }
        , { id: 'kailiao', header: "开料", width: cellWidth1, align: 'center', sortable: false, dataIndex: 'kailiao', renderer: renderValue, editor: new Ext.form.TextField({
            listeners: {
                focus: function() {
                    EditCellValue = null;
                    ThisCellOleValue = this.value;
                    CurrentModelRow = ModelRow;
                    CurrentEditOgId = Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('id')
                },
                blur: function() {
                    if (EditCellValue == null) {
                        EditCellValue = this.getValue();
                    }
                    if (EditCellValue != ThisCellOleValue) {
                        UpdateOrdersGridCellValue('kailiao', EditCellValue, CurrentEditOgId);
                    }
                },
                specialkey: function(textfield, e) {
                    if (e.getKey() == Ext.EventObject.ENTER) {
                        EditCellValue = null;
                        Order_MainGridPanel.getSelectionModel().selectNext();
                    }
                }
            }
        })
        }
         , { id: 'memo', header: "备注", width: 90, align: 'center', sortable: false, dataIndex: 'memo', renderer: renderValue, editor: new Ext.form.TextField({
             listeners: {
                 focus: function() {
                     EditCellValue = null;
                     ThisCellOleValue = this.value;
                     CurrentModelRow = ModelRow;
                     CurrentEditOgId = Order_MainGridPanel.getStore().getAt(CurrentModelRow).get('id')
                 },
                 blur: function() {
                     if (EditCellValue == null) {
                         EditCellValue = this.getValue();
                     }
                     if (EditCellValue != ThisCellOleValue) {
                         UpdateOrdersGridCellValue('memo', EditCellValue, CurrentEditOgId);
                     }
                 },
                 specialkey: function(textfield, e) {
                     if (e.getKey() == Ext.EventObject.ENTER || e.getKey() == Ext.EventObject.TAB) {
                         EditCellValue = null;
                         Order_MainGridPanel.getSelectionModel().selectNext();
                     }
                 }
             }
         })
         }
	]);

    /**
    *描述 : 渲染列，鼠标移该单元格上面，显示完整的值
    *参数 : value：单元格的值；
    */
    function renderGridID(value, metadate, record, colIndex, rowIndex) {
        if (colIndex < 9)
            return '<div style="text-align:left;color:#969292;"><span>' + "0" + (colIndex + 1) + '</span></div>';
        else
            return '<div style="text-align:left;color:#969292;"><span>' + (colIndex + 1) + '</span></div>';
    }

    /**
    *描述 : 渲染列，鼠标移该单元格上面，显示完整的值
    *参数 : value：单元格的值；
    */
    function renderValue(value, metadate, record, colIndex, rowIndex) {
        return '<div style="text-align:left;"><span title="' + (value == null || value == "" ? "" : value) + '">' + (value == null || value == "" ? "" : value) + '</span></div>';
    }

    // 定义一个主GridPanel存放订单列表信息
    Order_MainGridPanel = new Ext.grid.EditorGridPanel({
        id: "Order_MainGrid",
        height: parent.Ext.get("ContentFrame").getHeight() - 56,
        frame: false,
        loadMask: true,
        //animCollapse: false,
        renderTo: "divOrder_Main",
        clicksToEdit: 1,
        stripeRows: true,
        store: Order_MainStore,
        cm: Order_MainlistColumnModel,
        sm: smOrder_MainModel,
        trackMouseOver: true,
        border: false,
        //        enableColumnHide: false,
        hideHeaders: false,
        listeners: {
            beforeedit: function(e) {
                var currRecord = e.record;
                if (currRecord.get("auditPass") == 1)
                    e.cancel = true;
            }
        }
    });
    Order_MainLoad();

    // 订单信息加载
    function Order_MainLoad() {
        Order_MainStore.load({ params: { start: 0, limit: 500, order_id: order_id }, callback: function(r) { InitBlankRow() } });
    }

    function UpdateTotalValue(fieldname, fieldoldvalue, fieldvalue, rowindex) {
        var isSet = true;
        if (fieldvalue != null && fieldvalue != "") {
            var totalCount = 0;
            var tempArray = fieldvalue.split(",");
            if (tempArray != null) {
                var length = tempArray.length;
                for (var i = 0; i < length; i++) {
                    if (tempArray[i].split("/")[1] == "" || tempArray[i].split("/")[1] == null || isNaN(tempArray[i].split("/")[1])) {
                        Order_MainGridPanel.getStore().getAt(rowindex).set(fieldname, fieldoldvalue);
                        Order_MainGridPanel.getSelectionModel().selectRow(rowindex);
                        Order_MainGridPanel.getView().refresh();
                        Ext.MessageBox.alert("提示", "<span style='line-height:18px;'>非法数据！<br /><font color='Red'>本单元格的数据格式为“颜色/数量,颜色/数量”，且数量必须为整数！</font><br />数据已重置，请重新选择。</span>");
                        isSet = false;
                    }
                    if (!isSet)
                        break;
                    totalCount += parseInt(tempArray[i].split("/")[1]);
                }
                if (isSet) {
                    Order_MainGridPanel.getStore().getAt(CurrentModelRow).set('total', totalCount);
                    isUpdate = true;
                }
            }
        }
    }

    var ClientInfoRecordStore = new Ext.data.Store({
        //设定读取的地址
        proxy: new Ext.data.HttpProxy({ url: strPath + 'GGFW/DocumentsManage/ClientCommand.fwf?Method=SearchValidClientInfo' }),
        //设定读取的格式
        reader: new Ext.data.JsonReader({
            root: 'Records',
            id: 'client_id',
            totalProperty: 'totalCount',
            fields: [
                 { name: 'client_id' }
			    , { name: 'client_code' }
				, { name: 'client_name' }
           ]
        }),
        remoteSort: true
    });

    // 搜索结果
    var resultTpClientInfo = new Ext.XTemplate(
            '<table style="width:100%;"><tr style="background:#ccc;"><th>#</th><th>客户名称</th><th>客户编码</th></tr>',
            '<tpl for=".">',
            '<tr class="search-item"><td>{#}</td><td>{client_name}</td><td >{client_code}</td></tr>',
            '</tpl></table>'
        );

    cbClientInfo = new Ext.form.ComboBox({
        displayField: 'ClientInfo',
        loadingText: '加载中...',
        minChars: 1,
        width: topInputWidth,
        listWidth: 300,
        minListWidth: 300,
        deferHeight: true,
        baseCls: "x-plain",
        id: 'cbClientInfo',
        pageSize: 10,
        store: ClientInfoRecordStore,
        renderTo: 'divClientInfo',
        selectOnFocus: true,
        itemSelector: 'tr.search-item',
        typeAhead: false,
        mode: 'remote',
        triggerAction: 'all',
        tpl: resultTpClientInfo,
        readOnly: false,
        editable: true,
        emptyText: '--请选择客户--',
        listeners:
         {
             focus: function() {
                 EditCellValue = null;
                 ThisCellOleValue = this.getValue();
                 hidValue = document.getElementById("hid_client_id").value;
             },
             blur: function() {
                 if (EditCellValue == null) {
                     EditCellValue = this.getValue();
                 }
                 if (hidValue == document.getElementById("hid_client_id").value) {
                     if (EditCellValue != ThisCellOleValue) {
                         Ext.MessageBox.alert("提示", "<span style='line-height:18px;'>非法操作！<br /><font color='Red'>客户名必须通过下拉列表选择获取！</font><br />数据已重置，请重新选择。</span>");
                         cbClientInfo.setValue(ThisCellOleValue);
                     }
                 }
                 else
                     UpdateOrdersInfo('orders', 'client_id', document.getElementById("hid_client_id").value);
             },
             select: function selectvalue(combo, record, index) {
                 document.getElementById("hid_client_id").value = record.data.client_id;
                 document.getElementById("cbClientInfo").value = record.data.client_name;
                 EditCellValue = record.data.client_name;
             }
         }
    });
});

function btnSaveOrder_Click() {
    var ordergridFileds = "";
    var ordergridFiledsName = "";
    var ordergridFiledsValue = "";

    var order_order_po = document.getElementById("txt_order_po").value;
    var order_client_name = document.getElementById("cbClientInfo").value;
    var order_client_id = document.getElementById("hid_client_id").value;
    var order_date = document.getElementById("txt_order_date").value;

    var alertInfo = ""; //警告提示信息
    //提示信息
    if (order_order_po == null || order_order_po == "")
        alertInfo += "订单号不能为空！</br>";
    if (order_client_name == null || order_client_name == "" || order_client_name == "--请选择客户--")
        alertInfo += "客户名不能为空！</br>";
    if (order_client_name != null && order_client_name != "" && order_client_name != "--请选择客户--" && (order_client_id == null || order_client_id == ""))
        alertInfo += "客户标识获取失败！（请通过鼠标点击来选择客户名）</br>";
    if (order_date == null || order_date == "")
        alertInfo += "日期不能为空！</br>";
    if (alertInfo != null && alertInfo != "") {
        Ext.MessageBox.alert("提示", alertInfo);
        return;
    }
    var orderFileds = "order_po,client_id,order_dateξψ" + order_order_po + "ψ,ψ" + order_client_id + "ψ,ψ" + order_date + "ψ";
    var recordArray = Order_MainStore.getModifiedRecords();
    for (var i = 0; i < recordArray.length; i++) {
        ordergridFiledsName = "";
        ordergridFiledsValue = "";
        items = recordArray[i].getChanges();
        var j = 0;
        for (var key in items) {
            j++;
            if (items[key] == "" || items[key] == null || key == "pro_name" || key == "code")
                continue;
            ordergridFiledsName += key + ",";
            ordergridFiledsValue += "ψ" + items[key] + "ψ" + ","
        }

        if (ordergridFiledsName == "" || ordergridFiledsName == null)
            continue;
        else {
            ordergridFiledsName = ordergridFiledsName.substring(0, ordergridFiledsName.length - 1);
            ordergridFiledsValue = ordergridFiledsValue.substring(0, ordergridFiledsValue.length - 1);
        }
        if (ordergridFiledsName == "" || ordergridFiledsName == null)
            continue;
        else
            ordergridFileds += "order_id," + ordergridFiledsName + "ξ∮order_id∮," + ordergridFiledsValue;
        if (i == recordArray.length - 1)
            continue;
        ordergridFileds += "₃";
    }

    //Ajax交互
    var myMask = new Ext.LoadMask(Ext.getBody(), {
        msg: "正在保存数据..."
    });
    myMask.show();

    var strUrl = strPath + 'GGFW/DocumentsManage/OrderCommand.fwf?Method=SaveOrder'
    Ext.Ajax.request({
        url: strUrl,
        method: 'POST',
        params: {
            orderFileds: orderFileds
            , ordergridFileds: ordergridFileds
        },
        failure: function(response, options) {
            myMask.hide();
            ReturnValue = Ext.MessageBox.alert("警告", "网络异常或登录过期，请重新登录！");
        },
        success: function(response, options) {
            // 保存返回的信息
            myMask.hide();
            var json = response.responseText;
            var obj = parseJsonResult(json);

            if (!obj.Success) {
                showMessage("错误！", "保存数据出错！", obj.Message);
            }
            else {
                if (obj.Message != null && obj.Message.trim() != '') {
                    Ext.MessageBox.alert("警告", obj.Message);
                    return;
                }
                else {
                    alert('保存数据成功');
                    window.location.href('orderslist.aspx');
                    myMask.hide();
                }
            }
        }
    });
}

//更新订单表(orders)信息
function UpdateOrdersInfo(tab_name, filedname, filedvalue) {
    if (tab_name == "orders" && filedname == "order_po" && filedvalue == "") {
        Ext.MessageBox.alert("提示", "<span style='font-weight:bold;'>订单号(PO)</span>不能为空！</br>");
        document.getElementById("txt_order_po").value = OrderPo;
        return;
    }
    else if (tab_name == "orders" && filedname == "order_po" && filedvalue != "")
        OrderPo = filedvalue;
    else if (tab_name == "orders" && filedname == "order_date" && filedvalue == "") {
        Ext.MessageBox.alert("提示", "<span style='font-weight:bold;'>日期(DATE)</span>不能为空！</br>");
        document.getElementById("txt_order_date").value = OrderDate;
        return;
    }
    else if (tab_name == "orders" && filedname == "order_date" && filedvalue != "")
        OrderDate = filedvalue;
    var strUrl = strPath + 'GGFW/DocumentsManage/OrderCommand.fwf?Method=UpdateOrdersInfo';
    Ext.Ajax.request({
        url: strUrl,
        method: 'POST',
        timeout: 60000, //设定超时时间为60秒
        params: {
            OrderID: order_id,
            TabName: tab_name,
            FiledName: filedname,
            FiledValue: filedvalue
        },
        failure: function(response, options) {
            ReturnValue = Ext.MessageBox.alert("警告", "网络异常或登录过期，请重新登录！");
        },
        success: function(response, options) {
            var json = response.responseText;
            var obj = parseJsonResult(json);

            if (!obj.Success) {
                showMessage("错误！", "更新出现错误！请查看详细原因。", obj.Message);
            }
        }
    });
}

//更新订单表(ordersgrid)信息
function UpdateOrdersGridCellValue(filedname, filevalue, og_id) {

    var strUrl = strPath + 'GGFW/DocumentsManage/OrderCommand.fwf?Method=UpdateOrdersGridfield';

    Ext.Ajax.request({
        url: strUrl,
        method: 'POST',
        timeout: 60000, //设定超时时间为60秒
        params: {
            OgID: og_id,
            OrderID: order_id,
            FieldName: filedname,
            FieldValue: filevalue
        },
        failure: function(response, options) {
            ReturnValue = Ext.MessageBox.alert("警告", "网络异常或登录过期，请重新登录！");
        },
        success: function(response, options) {
            var json = response.responseText;
            var obj = parseJsonResult(json);

            if (!obj.Success) {
                showMessage("错误！", "更新出现错误！请查看详细原因。", obj.Message);
            } else if (obj.data[0] != null) {
                Order_MainGridPanel.getStore().getAt(CurrentModelRow).set('id', obj.data[0].id);
            }
        }
    });
}

function InitBlankRow() {
    CheckScrollBar(Order_MainStore.getTotalCount());
    for (var i = 0; i < parseInt(((parent.Ext.get("ContentFrame").getHeight() - 80) - 1) / 21) - Order_MainStore.getTotalCount(); i++)
        AddGridRow(false);
}

function AddGridRow(showScrollBar) {
    Order_MainStore.add(new Ext.data.Record({ id: 0 }));
    if (showScrollBar) {
        var c = Order_MainGridPanel.getView().scroller.dom;
        c.scrollTop = c.scrollHeight + 21;
        if (!isShowScrollBar)
            CheckScrollBar(Order_MainStore.data.items.length);
    }
}
function CheckScrollBar(gridCount) {
    if (gridCount > parseInt(((parent.Ext.get("ContentFrame").getHeight() - 80) - 1) / 21) && !isShowScrollBar) {
        isShowScrollBar = true;
        Order_MainGridPanel.getColumnModel().setColumnWidth(9, 73, false);
        Order_MainGridPanel.getView().refresh();
    }
}
